﻿@model IEnumerable<SmallJob.Model.Category>
@functions{
    public string displayCategory(List<SmallJob.Model.Category> categorys, bool isfirst)
    {
        string output = string.Empty;
        if (!isfirst)
        {
            output += "<ul class='dropdown-menu' role='menu'>";
        }
        foreach (var item in categorys)
        {
            if (item.Childrens.Count > 0)
            {
                output += "<li class='dropdown'><a class='dropdown-toggle disabled' data-toggle='dropdown' href=" + Url.Action("Category", "Provide", new { id = item.ID }) + ">" + item.Name + "<i class='icon-chevron-right pull-right'></i></a>";
                output += displayCategory(item.Childrens as List<SmallJob.Model.Category>, false);
                output += "</li>";
            }
            else
            {
                output += "<li><a href=" + Url.Action("Category", "Provide", new { id = item.ID }) + ">" + item.Name + "</a></li>";
            }

        }
        if (!isfirst)
        {
            output += "</ul>";
        }
        return output;
    }
}
<a class="header-menu dropdown-toggle" href="#" data-toggle="dropdown"><i class="icon-th-list"></i>&nbsp;Danh mục <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" aria="" labelledby="header-username-menu">
    @MvcHtmlString.Create(displayCategory(Model as List<SmallJob.Model.Category>, true))
   @* <li class="divider"></li>
    <li><a href="#">Khác</a></li>*@
</ul>
